package com.chujiekeji.test.api;

import com.loopj.android.http.RequestParams;
import com.loopj.android.http.TextHttpResponseHandler;

import org.xutils.http.body.MultipartBody;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;

import cz.msebera.android.httpclient.Header;

public class ChujieApi {
    /**
     * login account
     *
     * @param username username
     * @param pwd      pwd
     * @param handler  handler
     */
    public static void login(String username, String pwd, TextHttpResponseHandler handler) {
        RequestParams params = new RequestParams();
        params.put("phonenum", username);
        params.put("password", pwd);
        ApiHttpClient.post("duang/login/login", params, handler);
    }

    public static void fetchFenSi(int nextPage, int requestCount,int type, TextHttpResponseHandler handler) {
        RequestParams params = new RequestParams();
        params.put("nextPage", nextPage);
        params.put("requestCount", requestCount);
        params.put("type", type);
        ApiHttpClient.post("http://yungee.chujiekeji.com/api/page_fetch_user", params, handler);
    }
    public static void fetchPengYou(int nextPage, int requestCount,int type, TextHttpResponseHandler handler) {
        RequestParams params = new RequestParams();
        params.put("nextPage", nextPage);
        params.put("requestCount", requestCount);
        params.put("friendType", type);
        ApiHttpClient.post("duang/friend/queryFriend", params, handler);
    }

    public static void getNotice(TextHttpResponseHandler textHttpResponseHandler) {
    }

    public static void clearNotice(int flag, TextHttpResponseHandler textHttpResponseHandler) {
    }

    public static void getUserInfo(TextHttpResponseHandler requestUserInfoHandler) {
    }

    public static void updateUserIcon(File file, TextHttpResponseHandler requestUserInfoHandler) {
    }

    public static void fetchTask(int nextPage, int requestCount, TextHttpResponseHandler handler) {
        RequestParams params = new RequestParams();
        params.put("nextPage", nextPage);
        params.put("requestCount", requestCount);
        ApiHttpClient.post("/duang/task/allTask", params, handler);
    }
    public static void saveTask(String title, String content, String beginTime,
                                String endTime, String number, String reward,
                                String dealTypeStr, String categoryStr, String province,
                                String city, String area, List<String> files, TextHttpResponseHandler handler) {
        RequestParams params = new RequestParams();
        params.put("title", title);
        params.put("content", content);
        params.put("startTime", beginTime);
        params.put("endTime", endTime);
        params.put("number", Integer.parseInt(number));
        params.put("moneyReward", Integer.parseInt(reward));
        params.put("underLine", dealTypeStr);
        params.put("positionProvince", province);
        params.put("positionCity", city);
        params.put("positionDistrict", area);
        params.put("taskKind",categoryStr);
        if (files !=null && files.size()>0){
            File[] files1 =new File[files.size()];
            for (int i = 0; i < files.size(); i++) {
                files1[i] = new File(files.get(i));
            }
            try {
                params.put("images",files1,"multipart/form-data",null);
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
            ApiHttpClient.post("/duang/task/addTaskImages", params, handler);
        }else {
            ApiHttpClient.post("/duang/task/addTask", params, handler);
        }
    }

    public static void register(String realName, String nickName, String phone, String password, String email, String idNum, TextHttpResponseHandler handler) {
        RequestParams params = new RequestParams();
        params.put("realName", realName);
        params.put("nickName", nickName);
        params.put("phoneNum", phone);
        params.put("password", password);
        params.put("password", password);
        params.put("email", email);
        ApiHttpClient.post("duang/login/regeist", params, handler);
    }

    public static void addGuanzhu(String helpNum, TextHttpResponseHandler handler) {
        RequestParams params = new RequestParams();
        params.put("friendHelpNum", helpNum);
        ApiHttpClient.post("duang/friend/addFocus", params, handler);
    }
    public static void addFriend(String helpNum, TextHttpResponseHandler handler) {
        RequestParams params = new RequestParams();
        params.put("friendHelpNum", helpNum);
        ApiHttpClient.post("duang/friend/addFriend", params, handler);
    }

    public static void fetchFriendCircle(int nextPage, int requestCount, TextHttpResponseHandler mHandler) {
        RequestParams params = new RequestParams();
        params.put("nextPage", nextPage);
        params.put("requestCount", requestCount);
        ApiHttpClient.post("duang/friend/myFriendCircle", params, mHandler);
    }
}
